<?php
require_once("iana_catalog.php");
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<style type="text/css">
body {
color:#000;
font-family:arial,helvetica,verdana,sans-serif;
font-size:14px;
}
pre {
background: #ccd;
}
h2 {
border-bottom:1px solid #0cc;
}
</style>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>IANA Subtag Language Catalog test</title>
</head>
<body>
<h1>IANA Subtag Catalog Examples</h1>
<h2>Get subtag description providing subtag type</h2>
<pre>IANACatalog::queryCatalog("language","en");</pre>
<?php echo IANACatalog::queryCatalog("language","en");?>
<pre>IANACatalog::queryCatalog("language","EN");</pre>
<?php echo IANACatalog::queryCatalog("language","EN");?>
<pre>IANACatalog::queryCatalog("language","EN",true); //Case sensitive: returns false</pre>
<?php echo IANACatalog::queryCatalog("language","EN",true); //Case sensitive: returns false ?>
<pre>IANACatalog::queryCatalog("region","GB");</pre>
<?php echo IANACatalog::queryCatalog("region","GB");?>
<pre>IANACatalog::queryCatalog("region","005");</pre>
<?php echo IANACatalog::queryCatalog("region","005");?>
<pre>IANACatalog::queryCatalog("script","Cyrl");</pre>
<?php echo IANACatalog::queryCatalog("script","Cyrl");?>
<pre>IANACatalog::queryCatalog("script","cyrl",true); //Case sensitive: returns false</pre>
<?php echo IANACatalog::queryCatalog("script","cyrl",true); //Case sensitive: returns false ?>
<pre>IANACatalog::queryCatalog("script","cyrl",false); //Case insensitive (default): returns description</pre>
<?php echo IANACatalog::queryCatalog("script","cyrl",false); //Case insensitive (default): returns description ?>
<h2>Get subtag description regardless of subtag type</h2>
<p>IMPORTANT: Some keys are the same in different subtag types (languages and regions), but with different capitalization.</p>
<p>If you use a case insensitive search, you will only get the first subtag type. Subtags priority is: language, script, region, variant, grandfathered, redundant</p>
<pre>IANACatalog::queryFullCatalog("ast"); //language subtag </pre>
<?php echo IANACatalog::queryFullCatalog("ast"); //language subtag ?>
<pre>IANACatalog::queryFullCatalog("af"); // af=language subtag, AF=region subtag, but returns language because of the priority </pre>
<?php echo IANACatalog::queryFullCatalog("af"); // af=language subtag, AF=region subtag. Returns language because of the priority ?>
<pre>IANACatalog::queryFullCatalog("AF", true); //af=language subtag, AF=region subtag, but returns region because the search is case sensitive </pre>
<?php echo IANACatalog::queryFullCatalog("AF", true); //af=language subtag, AF=region subtag. Returns region because the search is case sensitive ?>
<pre>IANACatalog::queryFullCatalog("AF"); //af=language subtag, AF=region subtag, but returns language because the search is case insensitive and has higher priority </pre>
<?php echo IANACatalog::queryFullCatalog("AF"); //af=language subtag, AF=region subtag. Returns language because the search is case insensitive and has higher priority ?>
<pre>IANACatalog::queryFullCatalog("Zmth"); //Zmth=script subtag </pre>
<?php echo IANACatalog::queryFullCatalog("Zmth"); //Zmth=script subtag ?>
<h2>Get subtag type, given the value</h2>
<p>The same behavior described in the previous section applies</p>
<pre>IANACatalog::getSubtagType("ast"); //language subtag </pre>
<?php echo IANACatalog::getSubtagType("ast"); //language subtag ?>
<pre>IANACatalog::getSubtagType("af"); // af=language subtag, AF=region subtag, but returns language because of the priority </pre>
<?php echo IANACatalog::getSubtagType("af"); // af=language subtag, AF=region subtag. Returns language because of the priority ?>
<pre>IANACatalog::getSubtagType("AF", true); //af=language subtag, AF=region subtag, but returns region because the search is case sensitive </pre>
<?php echo IANACatalog::getSubtagType("AF", true); //af=language subtag, AF=region subtag. Returns region because the search is case sensitive ?>
<pre>IANACatalog::getSubtagType("AF"); //af=language subtag, AF=region subtag, but returns language because the search is case insensitive and has higher priority </pre>
<?php echo IANACatalog::getSubtagType("AF"); //af=language subtag, AF=region subtag. Returns language because the search is case insensitive and has higher priority ?>
<pre>IANACatalog::getSubtagType("Zmth"); //Zmth=script subtag </pre>
<?php echo IANACatalog::getSubtagType("Zmth"); //Zmth=script subtag ?>
<h2>Get associative arrays</h2>
<p>The full catalog is accesible as a public variable</p>
<pre>IANACatalog::$fullCatalog</pre>
<p>There's also an associative array with the allowed variants by prefix (language, or language+script), for validation purposed not implemented in the class</p>
<pre>IANACatalog::$variantsByPrefix</pre>
<h2>Convert locale code to meaningful description:</h2>
<p>Examples from <a href="http://www.w3.org/International/articles/language-tags/">the article at the W3C</a>:</p>
<pre>echo IANACatalog::convertLocale("en");</pre>
<?php echo IANACatalog::convertLocale("en");?>
<pre>echo IANACatalog::convertLocale("mas");</pre>
<?php echo IANACatalog::convertLocale("mas");?>
<pre>echo IANACatalog::convertLocale("fr-CA");</pre>
<?php echo IANACatalog::convertLocale("fr-CA");?>
<pre>echo IANACatalog::convertLocale("es-419");</pre>
<?php echo IANACatalog::convertLocale("es-419");?>
<pre>echo IANACatalog::convertLocale("zh-Hans");</pre>
<?php echo IANACatalog::convertLocale("zh-Hans");?>
<pre>echo IANACatalog::convertLocale("ast");</pre>
<?php echo IANACatalog::convertLocale("ast");?>
<pre>echo IANACatalog::convertLocale("az-Latn");</pre>
<?php echo IANACatalog::convertLocale("az-Latn");?>
<pre>echo IANACatalog::convertLocale("en-GB");</pre>
<?php echo IANACatalog::convertLocale("en-GB");?>
<pre>echo IANACatalog::convertLocale("es-005");</pre>
<?php echo IANACatalog::convertLocale("es-005");?>
<pre>echo IANACatalog::convertLocale("zh-Hant-HK");</pre>
<?php echo IANACatalog::convertLocale("zh-Hant-HK");?>
<pre>echo IANACatalog::convertLocale("sl-nedis");</pre>
<?php echo IANACatalog::convertLocale("sl-nedis");?>
<pre>echo IANACatalog::convertLocale("sl-rozaj");</pre>
<?php echo IANACatalog::convertLocale("sl-rozaj");?>
<pre>echo IANACatalog::convertLocale("sl-IT-nedis");</pre>
<?php echo IANACatalog::convertLocale("sl-IT-nedis");?>
<pre>echo IANACatalog::convertLocale("de-CH-1901");</pre>
<?php echo IANACatalog::convertLocale("de-CH-1901");?>
<pre>echo IANACatalog::convertLocale("zh-cmn");</pre>
<?php echo IANACatalog::convertLocale("zh-cmn");?>
</body>
</html>